package com.company.structural.facade_pattern.facade;

import com.company.structural.facade_pattern.abstract_facade.AbstractEncryptFacde;
import com.company.structural.facade_pattern.subsystem.CipherMachine;
import com.company.structural.facade_pattern.subsystem.FileReader;
import com.company.structural.facade_pattern.subsystem.FileWriter;

/**
 * 模运算加密外观
 * @ClassName EncryptFacade
 * @Author tiezheng.han
 * @Date 2020/9/1 11:12
 **/
public class EncryptFacade extends AbstractEncryptFacde {
    /**
     * 维持对子系统对象的引用
      */
    private FileReader reader;
    private CipherMachine cipherMachine;
    private FileWriter fileWriter;

    public EncryptFacade() {
        reader = new FileReader();
        cipherMachine = new CipherMachine();
        fileWriter = new FileWriter();
    }

    /**
     * 调用子系统对象的业务方法
     */
    @Override
    public void  fileEncrypt(String fileNameSrc,String fileNameDes){
        String plainStr = reader.read(fileNameSrc);
        String encryptSrt = cipherMachine.encrypt(plainStr);
        fileWriter.write(encryptSrt,fileNameDes);

    }
}
